<?php
// 本类由系统自动生成，仅供测试用途
class ZsxmAction extends Action {

	
	//预设  para一般自身的所有以及扩展的zabojingua东西
	//聚合
    private $all=array(
    	'mdmk'=>'Zsxm',//NB
  		'ttl'=>'招商项目',
  		'jn'=>array(),//NB
      //自己的全部+f的显示的东西
  		'para'=>array('zsxmid'=>'zsxmID','zsxmtm'=>'时间','zsxmsjqq'=>'商家QQ','zsxmsjtel'=>'商家联系','zsxmwa'=>'文案','zsxmyhq'=>'优惠券','zsxmyhqnum'=>'优惠券数量','zsxmlink'=>'链接','zsxmyj'=>'佣金','zsxmcsdl'=>'初始单量','zsxmfwf'=>'服务费','zsxmpdsl'=>'跑单数量','zsxmsfjs'=>'是否结算','zsxmjsje'=>'结算金额','zsxmaddtm'=>'添加时间','zsxmmdftm'=>'修改时间','zsxmquanjietu'=>'券截图'),//NB
  		//抛去不是zabojin的属性针对para
      'notself'=>array(),
       ##########modify 添加修改中不需要展示和理会的属性 针对para
      'no_update'=>array('zsxmid','zsxmaddtm','zsxmmdftm','zsxmsjqq','zsxmcsdl'),
      #####update的时候允许为空的值 针对zabojin刨掉不然显示的update字段后
      'allowempty'=>array('zsxmpdsl','zsxmjsje','zsxmyhqnum','zsxmquanjietu'),

      'hide_fld'=>array('zsxmid'),//NB
      'hide_cdt'=>array('zsxmid'),//NB
  		
    //   'spccdtls'=>array('spccdt_0'=>array('zsxmid<>0','zsxmID不为0【废话只是测试】')),
  		// 'odrls'=>array('zsxmnm'),
    //   'spccdt_dflt'=>array('spccdt_0'),
    //   'odr_dflt'=>array('zsxmnm'=>'ASC'),

      'spccdtls'=>array(),//NB
      'odrls'=>array('zsxmsfjs','zsxmaddtm'),//NB
      'spccdt_dflt'=>array(),//NB
      'odr_dflt'=>array('zsxmsfjs'=>'ASC','zsxmaddtm'=>'DESC'),//NB
      //hide的fld必须有，他们虽然不显示但是必须选择，这样才能在第一次进入query的时候，隐藏属性可以被调用，特别是id和fid
  		'fld_dflt'=>array('zsxmid','zsxmtm','zsxmsjtel','zsxmwa','zsxmyhq','zsxmyhqnum','zsxmlink','zsxmyj','zsxmfwf','zsxmpdsl','zsxmsfjs','zsxmjsje','zsxmquanjietu'),//NB
  		'cdt_dflt'=>array(),//NB
  		
  		'lmt_dflt'=>50,//NB
  		
  		'defaultls'=>1,//默认枚举//NB
  		##########view
  		'no_view'=>array('zsxmid'),
	   
      #########删除提醒
      'deleteconfirm'=>'确定要删除此条记录？',
      #####转义
      'transmean'=>array('zsxmsfjs'=>array('0'=>'否','1'=>'是')),//NB
      #####默认值
      'dfltvalue'=>array('zsxmsfjs'=>0),
      ########新增属性
      'linkage'=>array(),//如果ccc的变换需要转换成2015_ccc 就是2  否则如果是1 非2情况下联动没有值，不允许下拉，3联动不造成下拉有无
      ########这里是谁影响谁，用在AJAX联动 效果极佳
      'impactfactor'=>array(),
      
    );

    //公版
    public function query(){
    	header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');$zsxm=D('Zsxm');
      $arr_mls=$pb->query($this->all);$mls=$arr_mls['data'];

      $mlsnw=array();
      foreach($mls as $mv){
        if($mv['zsxmwa']){
          // $strPreg = '/<img src="([\s\S]*?)"\/>/';
          preg_match('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$mv['zsxmwa'],$match);
          $img=$match[0];
          if($img){
            $img=str_replace('<img', "<img style='height:80px;width:80px' ", $img);
            $mv['zsxmwa']=$img;
          }else{
            $mv['zsxmwa']=substr($mv['zsxmwa'], 0,20).'...';
          }
          
        }

        
        if($mv['zsxmyhq']){$mv['zsxmyhq']="<a href='".$mv['zsxmyhq']."' target='_blank'>".substr($mv['zsxmyhq'], 0,10).'...'."</a>";}
        if($mv['zsxmlink']){$mv['zsxmlink']="<a href='".$mv['zsxmlink']."' target='_blank'>".substr($mv['zsxmlink'], 0,10).'...'."</a>";}
        array_push($mlsnw,$mv);
      }
      $this->assign('mls',$mlsnw);

      //计算按月来
      //这个项目是2016-11月份开始的，所以从11月份开始
      //先计算当前的 年 月
      $year=date("Y",time());$month=date("m",time());
      for($yr=$year;$yr>=2016;$yr--){
        for($mt=12;$mt>=1;$mt--){
          if($yr==2016&&$mt<11){continue;}
          if($mt<10){$mt='0'.$mt;}
          $str=$yr."-".$mt;
          $arr_bonus=$zsxm->getmonthbonus($str);$bonus=$arr_bonus['data'];
          $zhangmu[$str]=$bonus;
        }
      }
      $this->assign('zhangmu',$zhangmu);

      $this->display('query');
  
    }

    public function liucheng(){
      header("Content-Type:text/html; charset=utf-8");
      $environment=D('Environment');$zsxmlc=D('Zsxmlc');
      $arr_usross=$environment->setenvironment(MODULE_NAME);$usross=$arr_usross['data'];

      $id=gp()['id'];
      $arr_zsxmlcls=$zsxmlc->getzsxmlclsbyzsxmid($id);$zsxmlcls=$arr_zsxmlcls['data'];
      $this->assign('zsxmlcls',$zsxmlcls);

      $this->assign('ttl','流程');
      $this->display('liucheng');
  
    }
    
    //公版
    public function view(){
    	header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');
    	$pb->view($this->all);
      $this->assign('ttl','查看');
		  $this->display('view');
    }
   
   	//公版
   	public function update(){
   		header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');

      $all=$this->all;
      if(gp()['id']==0){$all['dfltvalue']['zsxmtm']=date('Y-m-d',time());}
    	$pb->update($all);

      $this->assign('project',C('PROJECT'));
      

		  $this->display('update');
   	}

   	//公版
   	public function doupdate(){
   		header("Content-Type:text/html; charset=utf-8");
   		$pb=D('PB');$zsxm=D('Zsxm');$zsxmlc=D('Zsxmlc');

      $get=gp();
      
      if($get['zsxmwa']){$get['zsxmwa']=stripslashes($get['zsxmwa']);}
      

      
      $tm=tm();
      if($get['zsxmid']==0){
        $get['zsxmaddtm']=$tm;
        $get['zsxmmdftm']=$tm;
      }else{
        $get['zsxmmdftm']=$tm;
      }

   		$arr_pattern=$pb->doupdate($this->all,$get);
   		$data['pattern']=$arr_pattern['data'];

      
      if($get['zsxmid']==0){$arr_zsxmo=$zsxm->getlastzsxmo();$zsxmo=$arr_zsxmo['data'];$zsxmid=$zsxmo['zsxmid'];}else{$zsxmid=$get['zsxmid'];}
      $zsxmlc->add($tm,$zsxmid,getoffp(stripslashes($get['beizhu'])));
      

   		$this->ajaxReturn($data,'json');
   	}

   	//公版
   	public function dodelete(){
   		header("Content-Type:text/html; charset=utf-8");
   		$pb=D('PB');$zsxmlc=D('Zsxmlc');
   		$pb->dodelete($this->all);

      $zsxmlc->deletebyzsxmid(gp()['id']);
  		
   		$this->ajaxReturn($data,'json');
   	}

    public function dolinkage(){
      header("Content-Type:text/html; charset=utf-8");
      $nb=D('NB');
      $arr=$nb->dolinkage($this->all);
      
      $data=$arr['data'];
      
      $this->ajaxReturn($data,'json');
    }

    public function dogetzsxmobyzsxmid(){
      header("Content-Type:text/html; charset=utf-8");
      $zsxm=D('Zsxm');
      
      $zsxmid=gp()['id'];

      $arr_zsxmo=$zsxm->getzsxmobyzsxmid($zsxmid);$zsxmo=$arr_zsxmo['data'];
      $data['zsxmo']=$zsxmo;
      
      $this->ajaxReturn($data,'json');
    }

    public function getzsxmlsfoujiesuan(){
      header("Content-Type:text/html; charset=utf-8");
      $zsxm=D('Zsxm');

      $arr_zsxmls=$zsxm->getzsxmlsfoujiesuan();$zsxmls=$arr_zsxmls['data'];

      echo je($zsxmls);
    }

}